import scrapy
import socket

# 创建一个socket套接字，使用IPv4和TCP协议
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 设置socket选项，重用地址和端口
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# 监听本地6666端口
sock.bind(('0.0.0.0', 6666))
sock.listen(10)

# 等待客户端连接
while True:
    conn, addr = sock.accept()
    print('New connection from', addr)
    # 处理客户端请求
    data = conn.recv(1024)
    response = b'HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello world!'
    conn.sendall(response)
    conn.close()